<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>
<body>
    <button id="app">点击</button>
    <script>
        console.log("asdsa")
        
            var socket=new WebSocket('ws://127.0.0.1:9091')
            socket.onopen=function(){
               // alert("链接成功") 
              
                socket.send("你好123123")
            }
            socket.close=function(){
                alert("断开了链接")
            }
            socket.onmessage=function(res){
                console.log(res.data)
            //  socket.send("你好123123")
            }
            socket.onerror=function(){
               // alert("出错了")
            }
            socket.setConnectionLostTimeout(3000)
            
        var btn =document.getElementById("app")
        btn.onclick=function(){
            alert("..")
            socket.close()
            
        }
            </script>
    
</body>
</html>
